import React, { useContext } from 'react'

import List from './list'
import { Then } from '../redux';
import useContextMenu from '../hooks/useContextMenu';
import { indexof } from '../redux/util';
import fileHelper, { deleteFolder } from '../redux/fileHelper';

const FileList = () => {
    let clickedItem = useContextMenu([{
        label: '新建文件夹', click: () => {
            console.log(clickedItem.current)
        },
        typeString: 'radio',
        level: [0, 1]
    }, {
        label: '新建文件', click: () => {
        },
        level: [0, 1]
    }, {
        label: '删除', click: async () => {
            console.log(clickedItem.current)
            let index = clickedItem.current?.getAttribute("data-index").toString().split("_")
            console.log(index)
            let res = indexof([...index], state.reddirto)

            if (res) {
                let del = await deleteFolder(res.path)
                if (del) {
                    dispatch({ type: "deleteFile", index })
                }
            }
            // dispatch({ type: "deleteFile", index })
        },
        level: [2, 1]
    }, {
        label: '重命名', click: () => {

        },
        level: [2, 1]
    },], '#list_index')
    const { state, dispatch } = useContext(Then);
    return (
        <div id="list_index" className="list_index" data-level="0" data-index='-1'>

            <List index={0} reddirto={state.reddirto} ind={null}></List>

        </div>
    )
}


export default FileList